import BaseView from "../baseView.js";

export default class schedulesUpdate extends BaseView {
    //修改构造函数
    constructor(id, studentId) {
        super(id);
        //获得传过来的参数的值 并赋值给详情页面的属性this.studentId赋值
        this.studentId = studentId;
        //console.log("详细信息页面：studentId==>>"+studentId);
        //挂载数据
        this.mouted()
    }

    //挂载数据
    mouted() {
        //console.log("详细页面需要查询：="+this.studentId)
        //发送ajax
        $.ajax({
            type: "get",
            url: "/schedules/showSchedules/" + this.studentId,
            DataType: "json",
            success: (data) => {
                console.log(data)
                if (data.code == 1) {
                    let res = data.data;
                    $("#movieId").val(res.movieId);
                    $("#cinemasId").val(res.cinemasId);
                    $("#theaterId").val(res.theaterId);
                    $("#showTime").val(res.showTime);
                    $("#price").val(res.price);
                    //渲染页面
                    // myform.render();
                } else {
                    alert(data.msg)
                }
            }
        })
    }
    render() {
        $("#Content").html(`
             <div>
             <div style="margin: 30px 10px 0 20px ">
             <span class="layui-breadcrumb" style="visibility: visible;">
                 <a>学生管理系统/</a>/
                 <a>学生资料管理/</a>/
                 <a>详细信息</a>
              </span>
              <hr/>
             </div>
             <div>
             <form class="layui-form">
             <div class="layui-form-item">
             <label class="layui-form-label">电影名:</label>
               <div class="layui-input-block">
                 <input type="text" id="movieId" required   placeholder="请输入电影名"  class="layui-input">
               </div>
             </div>
             <div class="layui-form-item">
             <label class="layui-form-label">影院名:</label>
               <div class="layui-input-block">
                 <input type="text" id="cinemasId" required   placeholder="请输入影院名"  class="layui-input">
               </div>
             </div>
             <div class="layui-form-item">
             <label class="layui-form-label">放映厅:</label>
               <div class="layui-input-block">
                 <input type="text" id="theaterId" required   placeholder="请输入放映厅名"  class="layui-input">
               </div>
             </div>
             <div class="layui-form-item">
             <label class="layui-form-label">放映时间:</label>
               <div class="layui-input-block">
                 <input type="text" id="showTime" required   placeholder="请输入放映时间"  class="layui-input">
               </div>
             </div>
             <div class="layui-form-item">
             <label class="layui-form-label">价格:</label>
               <div class="layui-input-block">
                 <input type="text" id="price" required   placeholder="请输入价格"  class="layui-input">
               </div>
             </div>
             <div class="layui-form-item">
               <div class="layui-input-block">
               <button type="reset" class="layui-btn layui-btn-primary" id="update">修改</button>
                 <button type="reset" class="layui-btn layui-btn-primary" id="back">返回</button>
               </div>
             </div>
           </form>
             </div>
             
             </div>
            `)
    }
    handle() {
        $("#addLayuijs").html(`
       <script>
        layui.use('form', function(){
        var form = layui.form;
         //重新渲染表单
         form.render();
        });
        </script>
         `)

        $("#back").click(() => {
            window.location.hash = "#/main/schedulesList";
        })

        //修改
        $("#update").click(() => {
            //alert("修改");
            $.ajax({
                type: "put",
                url: "/Schedules/updatesSchedules",
                data: {
                    "_id": this.studentId,
                    "movieId": $("#movieId").val(),
                    "cinemasId": $("#cinemasId").val(),
                    "theaterId": $("#theaterId").val(),
                    "showTime": $("#showTime").val(),
                    "price": $("#price").val()
                },
                dataType: "json",
                success: (data) => {
                    if (data.code == 1) {
                        alert(data.msg);
                        //跳转页面
                        window.location.hash = "#/main/schedulesList"
                    } else {
                        alert(data.msg)
                    }
                }
            })
        })
    }
    


}